Fix duplicate logging of MsalUiRequiredException (in-repo copy of #3910)#3941
Merged
Conversation
4 tasks
bgavrilMS
approved these changes
Jul 13, 2026
MsalUiRequiredException is already logged by MSAL.NET internally, so re-logging it via Logger.TokenAcquisitionError in TokenAcquisition.cs produced a duplicate log entry for every exception. Removed the redundant logging in the two catch blocks that only rethrow/wrap the exception. Fixes #3528
1ec99d2 to
04e8ab9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In-repo copy of #3910 by @armin-azar, opened so the
azure-pipelinesapp runs the PR pipeline natively (fork PRs don't trigger it, and the required check is enforced by an enterprise ruleset that admin merge can't bypass).Original commits and authorship by @armin-azar are preserved unchanged. Once this merges, #3910 will be closed as landed via this branch.
Validated earlier on manually-queued ADO build 1663620 (succeeded).
Original PR description (#3910):
Fix duplicate logging of MsalUiRequiredException
Summary of the changes (Less than 80 chars)
Stop double-logging MsalUiRequiredException
Description
MsalUiRequiredException is already logged internally by MSAL.NET at error
level. Microsoft.Identity.Web additionally logged the same exception via
Logger.TokenAcquisitionErrorin two places in TokenAcquisition.cs, bothof which only rethrow/wrap the exception (no recovery logic depends on the
log call). This produced two log entries for a single MsalUiRequiredException,
as described in the issue.
This PR removes the redundant logging calls in those two catch blocks and
adds a comment explaining why nothing is logged there. All other
Logger.TokenAcquisitionError call sites (which handle exceptions MSAL does
not already log, e.g. certificate retry) are unchanged.
Added a unit test that reproduces the scenario from the issue (AcquireTokenSilent
called with no account/login hint, which MSAL throws MsalUiRequiredException for
synchronously) and asserts the log is not emitted.
Fixes #3528